package com.QK.cnstudy.entity;

import java.util.Date;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class WorkRecord {
    private int id;
    private String workName;
    private Long lastTime;
    private int openTimes;

    public void saveToDB(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("insert into work_record values (?,?,?,?)", new Object[] { getId(), getWorkName(),
                        getLastTime(), getOpenTimes() });
    }

    public void updateWorkRecord(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("update work_record set last_time =? , open_times =? where id=?", new Object[] {
                        (new Date()).getTime(), getOpenTimes() + 1, getId() });
    }

    public void setInfoFromCursor(Cursor cursor) {
        int tmp;
        if ((tmp = cursor.getColumnIndex("id")) != -1) {
            setId(cursor.getInt(tmp));
        }
        if ((tmp = cursor.getColumnIndex("work_name")) != -1) {
            setWorkName(cursor.getString(tmp));
        }
        if ((tmp = cursor.getColumnIndex("last_time")) != -1) {
            setLastTime(cursor.getLong(tmp));
        }
        if ((tmp = cursor.getColumnIndex("open_times")) != -1) {
            setOpenTimes(cursor.getInt(tmp));
        }
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getWorkName() {
        return workName;
    }

    public void setWorkName(String workName) {
        this.workName = workName;
    }

    public Long getLastTime() {
        return lastTime;
    }

    public void setLastTime(Long lastTime) {
        this.lastTime = lastTime;
    }

    public int getOpenTimes() {
        return openTimes;
    }

    public void setOpenTimes(int openTimes) {
        this.openTimes = openTimes;
    }

}
